package com.yuelao.yuelao_backend.service.impl;

import com.yuelao.yuelao_backend.common.BizException;
import com.yuelao.yuelao_backend.common.ErrorCode;
import com.yuelao.yuelao_backend.service.Web3Service;
import org.springframework.stereotype.Service;

import java.util.Arrays;
import java.util.List;
import java.util.Random;

@Service
public class Web3ServiceImpl implements Web3Service {

    private static final List<String> SUPPORTED_WALLETS = Arrays.asList("MetaMask", "Trust Wallet", "WalletConnect");
    private static final Random RANDOM = new Random();

    @Override
    public List<String> getSupportedWallets() {
        return SUPPORTED_WALLETS;
    }

    @Override
    public boolean connectWallet(String walletType) {
        if (!SUPPORTED_WALLETS.contains(walletType)) {
            throw new BizException(ErrorCode.PARAMS_ERROR, "不支持的钱包类型: " + walletType);
        }
        // 模拟连接逻辑
        return RANDOM.nextBoolean(); // 随机返回成功或失败
    }

    @Override
    public Double getExchangeRate() {
        // 模拟获取代币兑换汇率，例如 1 USDT = 6.5 - 7.5 CNY
        return 6.5 + (7.5 - 6.5) * RANDOM.nextDouble();
    }
}